From cca5e11f09daf635d0080f24b80dbd6ce190bd4d Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 5 Apr 2004 13:59:39 +0000 Subject: [PATCH] Add debug wrappers for str[n]dupt. --- defs.h | 5 +++++ util.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/defs.h b/defs.h index ffedceb68..20fd14bef 100644 --- a/defs.h +++ b/defs.h @@ -380,6 +380,8 @@ void *XMALLOC(size_t size, DEBUG_PARAMS ); void *XREALLOC(void *p, size_t s, DEBUG_PARAMS ); void XFREE(void *mem, DEBUG_PARAMS ); char *XSTRDUP(const char *s, DEBUG_PARAMS ); +char *XSTRNDUP(const char *src, size_t size, DEBUG_PARAMS ); +char *XSTRNDUPT(const char *src, size_t size, DEBUG_PARAMS ); char *XSTRAPPEND(char *src, const char *new, DEBUG_PARAMS ); void debug_mem_open(); void debug_mem_output( char *format, ... ); @@ -389,12 +391,15 @@ void debug_mem_close(); #define xrealloc(p, s) XREALLOC(p,s,__FILE__,__LINE__) #define xfree(mem) XFREE(mem, __FILE__, __LINE__) #define xstrdup(s) XSTRDUP(s, __FILE__, __LINE__) +#define xstrndup(s, z) XSTRNDUP(s, z, __FILE__, __LINE__) +#define xstrndupt(s, z) XSTRNDUPT(s, z, __FILE__, __LINE__) #define xstrappend(src,new) XSTRAPPEND(src, new, __FILE__, __LINE__) #define xxcalloc XCALLOC #define xxmalloc XMALLOC #define xxrealloc XREALLOC #define xxfree XFREE #define xxstrdup XSTRDUP +#define xxstrndupt XSTRNDUPT #define xxstrappend XSTRAPPEND #endif /* DEBUG_MEM */ diff --git a/util.c b/util.c index 9166ca4c4..dfad3fb36 100644 --- a/util.c +++ b/util.c @@ -138,7 +138,11 @@ xstrdup(const char *s) * Duplicate at most sz bytes in str. */ char * +#ifdef DEBUG_MEM +XSTRNDUP(const char *str, size_t sz, DEBUG_PARAMS ) +#else xstrndup(const char *str, size_t sz) +#endif { size_t newlen; char *newstr; @@ -160,7 +164,11 @@ xstrndup(const char *str, size_t sz) * while copying. */ char * +#ifdef DEBUG_MEM +XSTRNDUPT(const char *str, size_t sz, DEBUG_PARAMS ) +#else xstrndupt(const char *str, size_t sz) +#endif { size_t newlen; char *newstr; -- 2.30.2